package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ImgUtils;
import com.ruoyi.system.domain.vo.ProductlistVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ProductlistMapper;
import com.ruoyi.system.domain.Productlist;
import com.ruoyi.system.service.IProductlistService;

/**
 * 底图表Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-30
 */
@Service
public class ProductlistServiceImpl implements IProductlistService {
    @Autowired
    private ProductlistMapper productlistMapper;

    /**
     * 查询底图表
     *
     * @param productId 底图表主键
     * @return 底图表
     */
    @Override
    public Productlist selectProductlistByProductId(Long productId) {
        Productlist productlist = productlistMapper.selectProductlistByProductId(productId);
        String productImage = productlist.getProductImage();
        String[] splitImg = productImage.split(",");
        productlist.setProductImage(splitImg[0]);
        return productlist;
    }

    @Override
    public Productlist selectProductByProductIdSplitImg(Long productId) {
        return productlistMapper.selectProductlistByProductId(productId);
    }



    /**
     * 查询底图表列表
     *
     * @param productlist 底图表
     * @return 底图表
     */
    @Override
    public List<Productlist> selectProductlistList(ProductlistVo productlist) {
        List<Productlist> productList = productlistMapper.selectProductlistList(productlist);
        for (Productlist item : productList) {
            String productImage = item.getProductImage();
            String[] splitImg = productImage.split(",");
            item.setProductImage(splitImg[0]);
        }

        return productList;
    }

    /**
     * 新增底图表
     *
     * @param productlist 底图表
     * @return 结果
     */
    @Override
    public int insertProductlist(Productlist productlist) {
        productlist.setCreateTime(DateUtils.getNowDate());
        String imagePath = productlist.getProductImage();
        imagePath = imagePath.replace("\\", "/");

        productlist.setProductImage(imagePath);

        return productlistMapper.insertProductlist(productlist);

    }

    /**
     * 修改底图表
     *
     * @param productlist 底图表
     * @return 结果
     */
    @Override
    public int updateProductlist(Productlist productlist) {
        return productlistMapper.updateProductlist(productlist);
    }

    /**
     * 批量删除底图表
     *
     * @param productIds 需要删除的底图表主键
     * @return 结果
     */
    @Override
    public int deleteProductlistByProductIds(Long[] productIds) {
        return productlistMapper.deleteProductlistByProductIds(productIds);
    }

    /**
     * 删除底图表信息
     *
     * @param productId 底图表主键
     * @return 结果
     */
    @Override
    public int deleteProductlistByProductId(Long productId) {
        return productlistMapper.deleteProductlistByProductId(productId);
    }
}
